var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     content:'',
     phoneNumber:'',
     selectName:'',
     selectId:'',
     haspropuse:false,
     typeArray:[],
     jubaoDisplay:false,
     prosUserId:'',
     selectText:''
  },
 getContent:function(event){
  //  console.log(event)
   this.setData({
     content:event.detail.value
   })
 },
 showType:function(event){
   console.log('已点击获取举报类型按钮')
   this.setData({
     jubaoDisplay:!this.data.jubaoDisplay
   })
 },
  getTelephoneNumber:function(event){
  //  console.log(event)
    this.setData({
      phoneNumber:event.detail.value
    })
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     try{
       this.setData({
         prosUserId:options.id
       })
     }catch(err){
        wx.showToast({
          title: '获取被举报人数据失败重试',
          icon:'none'
        })
     }
  }, 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that=this
    wx.request({
      url: app.globalData.baseUrl + 'prosecution/type',
      method: 'GET',
      header: {
        'cookie': 'JSESSIONID=' + wx.getStorageSync('sessionID')
      },
      success: function (res) {
       
        console.log(res)
        var resData=res.data.data
        for(var i=0;i<resData.length;i++){
          var name='typeArray['+i+'].name'
          var id='typeArray['+i+'].id'
          that.setData({
            [name]:resData[i].name,
            [id]:resData[i].id
          })
        }
      }
    })
  },
  select:function(event){
     console.log(event)
     this.setData({
        jubaoDisplay:!this.data.jubaoDisplay,
        selectName:event.currentTarget.dataset.name,
        selectId:event.currentTarget.dataset.id
     })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
   
  },
  submit:function(event){
    var that=this
    console.log(that.data.prosUserId)
    console.log(that.data.content)
    console.log(that.data.selectId)

    if (!this.data.haspropuse) {
      wx.request({
        url: app.globalData.baseUrl + 'prosecution/prosecution',
        method: 'POST',
        data: {
          prosUserId:that.data.prosUserId,
          content: that.data.content,
          typeId:that.data.selectId,
          telephone: that.data.phoneNumber
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded',
          'cookie': 'JSESSIONID=' + wx.getStorageSync('sessionID')
        },
        success: function (res) {
          console.log(res)
          if (res.data.msg == '请求成功') {
            wx.showToast({
              title: '举报成功，请等待反馈',
              
            })
            that.setData({
              haspropuse:true
            })
            wx.redirectTo({
              url: '../jubaoSuccess/jubaoSuccess',
            })
          }else{
            wx.showToast({
              title:res.data.msg,
              icon:'none'
            })
          }
        }
      })


    }else{
      wx.showToast({
        title: '您举报的太快了',
        icon:'null'
      })
    }
      
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})